﻿using System.Linq;
using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.Core.DapperWrapper.SqlServer;
using ZilLion.Service.WeChatMall.Domain.Entitys.Orders;
using ZilLion.Service.WeChatMall.Domain.Repositorys.Interface.Order;

namespace ZilLion.Service.WeChatMall.Domain.Repositorys.Order
{
    public class OrderSinceDeliveryRepository : SqlServerRespository<OrderDeliverySinceEntity>,
        IOrderSinceInfoRepository
    {
        public OrderSinceDeliveryRepository()
        {
            Context = new WechatMallContext();
        }

        public OrderDeliverySinceEntity GetOrderSinceDeliveryInfo(string sno)
        {
            var querysql = DapperHelper.CreateColSqlByMap<OrderDeliverySinceEntity>();
            var sql =
                $@"SELECT {querysql}
                FROM  weiscddjfxxt                
                where ddlsh =@sno";
            return GetList(sql, new {sno}).FirstOrDefault();
        }

        public void SaveOrderSinceDelivery(OrderDeliverySinceEntity entity, OrderMainInfoDto orderMain,
            UnitOfWork unit = null)
        {
            DapperHelper.Execute("delete from weiscddjfxxt where ddlsh=@sno", Context, unit,
                new {sno = orderMain.Sno});
            Add(entity, unit);
        }
    }
}